package com.yxx.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yxx.annotation.OptLogger;
import com.yxx.annotation.VisitLogger;
import com.yxx.entityModel.vo.Result.PageResult;
import com.yxx.entityModel.vo.Result.ResponseResult;
import com.yxx.entityModel.vo.query.PhotoQuery;
import com.yxx.entityModel.vo.request.PhotoInfoRequest;
import com.yxx.entityModel.vo.request.PhotoRequest;
import com.yxx.entityModel.vo.response.AlbumBackResponse;
import com.yxx.entityModel.vo.response.PhotoBackResponse;
import com.yxx.service.PhotoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

import static com.yxx.constant.OptTypeConstant.*;

/**
 * 照片控制器
 * @author yuxiangxun
 * @date 2025/2/1
 * @apiNote
 */
@Api(tags = "照片模块")
@RestController
public class PhotoController {

    @Resource
    private PhotoService photoService;

    /**
     * 查看后台照片列表
     * @param photoQuery 照片查询条件
     * @return 后台照片列表
     */
    @ApiOperation(value = "查看后台照片列表")
    @GetMapping("/admin/photo/list")
    @SaCheckPermission("web:photo:list")
    public ResponseResult<PageResult<PhotoBackResponse>> PhotoBackListVO(PhotoQuery photoQuery){
        return ResponseResult.success(photoService.PhotoBackListVO(photoQuery));
    }

    /**
     * 查看照片相册信息
     * @param albumId
     * @return
     */
    @ApiOperation(value = "查看照片相册信息")
    @SaCheckPermission("web:photo:list")
    @GetMapping("/admin/photo/album/{albumId}/info")
    public ResponseResult<AlbumBackResponse> getAlbumInfo(@PathVariable("albumId") Integer albumId){
        return ResponseResult.success(photoService.getAlbumInfo(albumId));
    }

    /**
     * 上传照片
     * @param file
     * @return
     */
    @OptLogger(value = UPLOAD)
    @ApiOperation(value = "上传照片")
    @ApiImplicitParam(name = "file", value = "照片", required = true, dataType = "MultipartFile")
    @SaCheckPermission("web:photo:upload")
    @PostMapping("/admin/photo/upload")
    public ResponseResult<String> uploadPhoto(@RequestParam("file")MultipartFile file){
        return ResponseResult.success(photoService.uploadPhoto(file));
    }

    /**
     * 添加照片
      * @param photoRequest
     * @return
     */
    @OptLogger(value = ADD)
    @ApiOperation(value = "添加照片")
    @SaCheckPermission("web:photo:add")
    @PostMapping("/admin/photo/add")
    public ResponseResult<?> addPhoto(@Validated @RequestBody PhotoRequest photoRequest){
        photoService.addPhoto(photoRequest);
        return ResponseResult.success();
    }

    /**
     * 修改照片信息
     * @param photoInfoRequest
     * @return
     */
    @OptLogger(value = UPDATE)
    @ApiOperation(value = "修改照片信息")
    @SaCheckPermission("web:photo:update")
    @PutMapping("/admin/photo/update")
    public ResponseResult<?> updatePhoto(@Validated @RequestBody PhotoInfoRequest photoInfoRequest){
        photoService.updatePhoto(photoInfoRequest);
        return ResponseResult.success();
    }

    /**
     * 删除照片
     * @param photoIdList
     * @return
     */
    @OptLogger(value = DELETE)
    @ApiOperation(value = "删除照片")
    @SaCheckPermission("web:photo:delete")
    @DeleteMapping("/admin/photo/delete")
    public ResponseResult<?> deletePhoto(@RequestBody List<Integer> photoIdList){
        photoService.deletePhoto(photoIdList);
        return ResponseResult.success();
    }

    /**
     * 移动照片
     * @param photoRequest
     * @return
     */
    @OptLogger(value = UPDATE)
    @ApiOperation(value = "移动照片")
    @SaCheckPermission("web:photo:move")
    @PutMapping("/admin/photo/move")
    public ResponseResult<?> movePhoto(@Validated @RequestBody PhotoRequest photoRequest){
        photoService.movePhoto(photoRequest);
        return ResponseResult.success();
    }

    /**
     * 查看照片列表
     * @param albumId
     * @return
     */
    @VisitLogger(value = "照片")
    @ApiOperation(value = "查看照片列表")
    @GetMapping("/photo/list")
    public ResponseResult<Map<String,Object>> PhotoListVO(@RequestParam Integer albumId){
        return ResponseResult.success(photoService.photoListVO(albumId));
    }
}
